package org.NooLab.itexx.app.controller;

import java.io.IOException;
import java.util.ArrayList;

import org.NooLab.itexx.app.config.ITexxAppPropertiesIntf;
import org.NooLab.utilities.files.BareBonesBrowserLaunch;
import org.NooLab.utilities.files.DFutils;
import org.NooLab.utilities.resources.ResourceLoader;
import org.NooLab.utilities.strings.StringsUtil;

public class Documentary {

	
	public Documentary(){
		
		checkForExportedFiles() ;
	}
	
	
	private void checkForExportedFiles() {
		// 
		
	}


	public static void showBasicInfo( ITexxAppPropertiesIntf appProperties ) {
		// 
		
		String docuMainDoc, basicPath =  appProperties.getOwnBinPath();
		
		basicPath = StringsUtil.replaceall(basicPath, "\\", "/");
		if (basicPath.toLowerCase().contains("/bin")){
			basicPath = DFutils.getParentDir(basicPath) ;
		}
		
		docuMainDoc = DFutils.createPath( basicPath, "common/documentation/");
		docuMainDoc = DFutils.createPath( docuMainDoc, "index.htm");

		try {
			
			if (DFutils.fileExists(docuMainDoc)){
				BareBonesBrowserLaunch.openURL( docuMainDoc );
			}
			// uses: java.awt.Desktop.getDesktop().browse( java.net.URI.create(docuMainDoc));
			
		} catch (Exception e) {
			System.err.println(e.getMessage());

		}
		
	}


	public static void exportDocuments(ITexxAppPropertiesIntf appProperties) throws IOException {
		
		ArrayList<String> dfiles ;
		String docuMainDoc, docuPath="",basicPath =  appProperties.getOwnBinPath();
		
		basicPath = StringsUtil.replaceall(basicPath, "\\", "/");
		if (basicPath.toLowerCase().contains("/bin")){
			basicPath = DFutils.getParentDir(basicPath) ;
		}
		
		docuPath = DFutils.createPath( basicPath, "common/documentation/");
		
		docuMainDoc = DFutils.createPath( docuPath, "index.htm");
		
		if (DFutils.fileExists(docuMainDoc)){
			return;
		}
		
		// export it
		
		String resourcePath = "org/NooLab/itexx/resources/documentation/";
		
		ResourceLoader rL = new ResourceLoader();
		rL.setJarFileName( appProperties.getJarFileName() );
		dfiles = rL.findFilesInJar( appProperties.getOwnBinPath(), appProperties.getClassOfMain(), resourcePath, ".htm") ;
		
		String[] df = rL.filesInJar( appProperties.getOwnBinPath(), appProperties.getClassOfMain(), ".htm");
		int n = df.length ;
		
	}

}
